#Boa:Dialog:Dialog2

import wx
import consultasBD

def create(parent):
    return Dialog1(parent)

[wxID_DIALOG1, wxID_DIALOG1LISTBOX1, 
] = [wx.NewId() for _init_ctrls in range(2)]

class Dialog1(wx.Dialog):
    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Dialog.__init__(self, id=wxID_DIALOG1, name='', parent=prnt,
              pos=wx.Point(374, 167), size=wx.Size(400, 250),
              style=wx.DEFAULT_DIALOG_STYLE, title='Busca Color')
        self.SetClientSize(wx.Size(384, 214))

        self.listBox1 = wx.ListBox(choices=[], id=wxID_DIALOG1LISTBOX1,
              name='listBox1', parent=self, pos=wx.Point(8, 8),
              size=wx.Size(344, 152), style=0)
        self.listBox1.Bind(wx.EVT_LISTBOX_DCLICK, self.OnListBox1ListboxDclick,
              id=wxID_DIALOG1LISTBOX1)
        self.id=""
        self.color=""

    def __init__(self, parent):
        self._init_ctrls(parent)

    def hacebusquedacolor(self,codigo):
        nombre = "nombre like '%"+codigo+"%'"
        codigo = "idcolor like '%"+codigo+"%'"
        textobuscado = ""+nombre+" or "+codigo+""
        print ""+textobuscado+"" 
        resultado = consultasBD.executaSQL(self,'*','colores',str(textobuscado))
        for r in resultado:
#            self.listBox1.Append(''+str(r[0])+'*********'+str(r[1]))
            self.listBox1.Append(str(r[1])+" / "+str(r[0]))

    def OnListBox1ListboxDclick(self, event):
        item = self.listBox1.GetStringSelection()
        self.color = item.split(" / ")[0]
        self.id = item.split(" / ")[1]
        self.Close()
    
    def Muestraid(self):
        return self.id
